function [] = displayEstimates(runId)

%%% Add paths
addpath('../general_funcs');
addpath('../consumerAdoptions');
addpath('../providerAdoptions');
addpath('../providerExits');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Get input / output paths
config = getConfig_jointProcess(runId);
outputFolder = createFolderIfNotExist(sprintf('%s/estimates', config.runFolder)); 

% Get config_consumerAdoptions and config_providerAdoptions: necessary input for make_Xdynamic_xxx functions
indivConfigs.consumerAdoptions = getConfig_consumerAdoptions(config.runId_consumerAdoptions);
indivConfigs.providerAdoptions  = getConfig_providerAdoptions(config.runId_providerAdoptions);
indivConfigs.providerExits      = getConfig_providerExits(config.runId_providerExits);

indivRunFolders.providerAdoptions  = config.runFolder_providerAdoptions;
indivRunFolders.providerExits      = config.runFolder_providerExits;
indivRunFolders.consumerAdoptions = config.runFolder_consumerAdoptions;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Display estimates for consumerAdoptions model
disp('===== CONSUMER ADOPTIONS =====');
load(sprintf('%s/results.mat', indivRunFolders.consumerAdoptions), 'params_hat', 'params_ses', 'modelFits');

%%% Load data to get paramNames
load(sprintf('%s/runData.mat', indivRunFolders.consumerAdoptions));
paramNames = get_param_names_consumerAdoptions(data);
sumY_consumerAdoptions = sum(data.Y(:));
clear data;

% Store LL and NumParams
LL1 = modelFits.LL;
NumParams1 = length(paramNames);

% Make table of estimates and display it
M1 = reportSubmodelResults(paramNames, params_hat, params_ses, modelFits, {}, true);
clear params_hat params_ses modelFits;
disp(M1);
writetable(M1, sprintf('%s/consumerAdoptions.csv', outputFolder), 'WriteRowNames', true);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Display estimates for providerAdoptions model
disp('===== PROVIDER ADOPTIONS =====');
load(sprintf('%s/results.mat', indivRunFolders.providerAdoptions), 'params_hat', 'params_ses', 'modelFits');

%%% Load data to get paramNames
load(sprintf('%s/runData.mat', indivRunFolders.providerAdoptions));
paramNames = get_param_names_providerAdoptions(data);
sumY_providerAdoptions = sum(data.Y(:));
clear data;

% Store LL and NumParams
LL2 = modelFits.LL;
NumParams2 = length(paramNames);

% Make table of estimates and display it
M1 = reportSubmodelResults(paramNames, params_hat, params_ses, modelFits, {}, true);
clear params_hat params_ses modelFits;
disp(M1);
writetable(M1, sprintf('%s/providerAdoptions.csv', outputFolder), 'WriteRowNames', true);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Display estimates for providerExits model
disp('===== PROVIDER EXITS =====');
load(sprintf('%s/results.mat', indivRunFolders.providerExits), 'params_hat', 'params_ses', 'modelFits');

%%% Load data to get paramNames
load(sprintf('%s/runData.mat', indivRunFolders.providerExits));
paramNames = get_param_names_providerExits(data);
sumY_providerExits = sum(data.Y(:));
clear data;

% Store LL and NumParams
LL3 = modelFits.LL;
NumParams3 = length(paramNames);

% Make table of estimates and display it
M1 = reportSubmodelResults(paramNames, params_hat, params_ses, modelFits, {}, true);
clear params_hat params_ses modelFits;
disp(M1);
writetable(M1, sprintf('%s/providerExits.csv', outputFolder), 'WriteRowNames', true);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Display model-level things (LL, AIC, BIC...)
warning('Here I entered manually the number of observations, which enters the calculation of BIC!');

if strcmp(indivConfigs.consumerAdoptions.runFolder(1:29), '../../results/continuous_time')
	myTimeLevel = 'ctsTime';
else if strcmp(indivConfigs.consumerAdoptions.runFolder(1:23), '../../results/day_level')
	myTimeLevel = 'day';
else if strcmp(indivConfigs.consumerAdoptions.runFolder(1:24), '../../results/week_level')
	myTimeLevel = 'week';
else
	error('Unknown timeLevel');
end; end; end;
disp(sprintf('Time level: %s', myTimeLevel))


%%%%%
% ctsTime-level model
if strcmp(myTimeLevel, 'ctsTime')
	NumObs = 32521*2014;
end

% day-level model
if strcmp(myTimeLevel, 'day')
	NumObs = 476*2014;
end

% week-level
if strcmp(myTimeLevel, 'week')
	NumObs = 68*2014;
	LL1 = LL1 - sumY_consumerAdoptions * log(7);
	LL2 = LL2 - sumY_providerAdoptions * log(7);
	LL3 = LL3 - sumY_providerExits * log(7);
end

sumY_consumerAdoptions
sumY_providerAdoptions
sumY_providerExits
%%%%%

LL = LL1 + LL2 + LL3;
NumParams = NumParams1 + NumParams2 + NumParams3
AIC = 2*NumParams - 2*LL;
BIC = NumParams*log(NumObs) - 2*LL;

LL1
LL2
LL3	
LL
AIC
BIC
NumParams
NumObs

M1 = table(LL, AIC, BIC, NumParams, NumObs);
writetable(M1, sprintf('%s/modelFits.csv', outputFolder), 'WriteRowNames', true);

end
